//
//  GridViewCell.m
//  LotteryClient
//
//  Created by Sunyon 14-4-23.
//  Copyright (c) 2014年 CTTC. All rights reserved.
//

#import "UIGridViewCell.h"

@interface UIGridViewCell ()

@end

@implementation UIGridViewCell
@synthesize titleLabel;
+ (instancetype)cellWithTitle:(NSString *)title
			  image:(UIImage *)image
		 hightImage:(UIImage *)hightImage
{

	UIGridViewCell *newCell = [[self class] buttonWithType:UIButtonTypeCustom];
	[newCell setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];


//	[newCell setTitle:title forState:UIControlStateNormal];

	
		newCell.title = title;
	CGRect frame = newCell.frame;

	if (image)
	{
		[newCell setImage:image forState:UIControlStateNormal];
		[newCell setImage:hightImage forState:UIControlStateHighlighted];
		
		frame.origin = CGPointMake(frame.origin.x, newCell.frame.size.height/5*4);
		frame.size = CGSizeMake(frame.size.width, newCell.frame.size.height/5);
	}

	
	UILabel *label = [[UILabel alloc] initWithFrame:frame];
	label.text = title;
	label.font = [UIFont systemFontOfSize:14];
	label.textAlignment = NSTextAlignmentCenter;
	newCell.titleLabel = label;
	[newCell addSubview:label];

	

	return newCell;
}

+ (instancetype)cellWithURLImage:(UIImage *)placeHolderImg
                 image:(NSURL *)imageURL
{
    UIGridViewCell *newCell = [[self class] buttonWithType:UIButtonTypeCustom];
	[newCell setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
	[newCell sd_setImageWithURL:imageURL
                    forState:UIControlStateNormal
            placeholderImage:placeHolderImg];

	
	CGRect frame = newCell.frame;
	frame.origin = CGPointMake(frame.origin.x, newCell.frame.size.height/5*4);
    frame.size = CGSizeMake(frame.size.width, newCell.frame.size.height/5);
		
	UILabel *label = [[UILabel alloc] initWithFrame:frame];
	label.font = [UIFont systemFontOfSize:14];
	label.textAlignment = NSTextAlignmentCenter;
	newCell.titleLabel = label;
	[newCell addSubview:label];
	newCell.titleLabel.hidden = YES;

    return newCell;
}



- (void)layoutSubviews
{
	[super layoutSubviews];
    CGRect frame = self.bounds;
    if (!self.isHiddenTitle)
    {
		if (self.imageView.image)
		{
			[self setImageEdgeInsets:UIEdgeInsetsMake(5,5,self.frame.size.height/5+5,5)];
			self.imageView.frame = CGRectMake(5, 
											  5,
											  self.width - 10, 
											  self.frame.size.height/5*4 - 5);
			frame.origin = CGPointMake(0, self.frame.size.height/5*4 - 5);
			frame.size = CGSizeMake(frame.size.width, self.frame.size.height/5);
		}

        self.titleLabel.frame = frame;
		self.titleLabel.text = self.title;
		self.titleLabel.hidden = self.isHiddenTitle;
		
    }
}


@end
